package com.situ.water_read.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.situ.water_read.pojo.RdVolume;
import com.situ.water_read.mapper.RdVolumeMapper;
import com.situ.water_read.service.RdVolumeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.situ.water_user.mapper.UsUserMapper;
import com.situ.water_user.pojo.UsUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Angel
 * @since 2020-12-01
 */
@Service
public class RdVolumeServiceImpl extends ServiceImpl<RdVolumeMapper, RdVolume> implements RdVolumeService {
    @Autowired
    RdVolumeMapper mapper;
    @Autowired
    UsUserMapper usmapper;
    @Override
    public int addvolume(RdVolume volume) {
        int i = mapper.insert(volume);
        return i;
    }

    @Override
    public List<RdVolume> queryall() {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("Disabled",0);
        return mapper.selectList(wrapper);
    }

    @Override
    public int updatevolumeId(String[] checkval,Integer volumeID) {
        UsUser user=new UsUser();
        int num=0;
        for(int i=0;i<checkval.length;i++) {
//            QueryWrapper wrapper=new QueryWrapper();
//            wrapper.eq("userno",user.getUserno());
            System.out.println(checkval[i]);
            user.setUserno(checkval[i]);
            user.setVolumeID(volumeID);
            user.setVolumeOrderIndex(null);
            //usmapper.selectList(checkval[i])
            num = usmapper.updateById(user);

        }
        return num;
    }

    @Override
    public int updateOrderId(UsUser user) {
        return usmapper.updateById(user);
    }

    @Override
    public List<UsUser> querybyId(QueryWrapper wrapper) {
        return usmapper.selectList(wrapper);
    }

    @Override
    public int queryCount() {
        Integer count = usmapper.selectusercount();
        return count;
    }
    @Override
    public Map queryUserNo(String userNo) {
        return mapper.queryUserNo(userNo);
    }

    /**
     * 查询该表册下的用户
     * @param delId
     * @return
     */
    @Override
    public List<UsUser> selectUserbyId(Integer delId) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("VolumeID",delId);
        return usmapper.selectList(wrapper);
    }

    @Override
    public void updateUserByVolume(UsUser user) {
        mapper.updateUserByVolume(user);
    }

    @Override
    public void deletevolume(Integer delId) {
        RdVolume volume=new RdVolume();
        volume.setDisabled(true);
        volume.setId(delId);
        mapper.updateById(volume);
    }
}
